public static List<int> FindChange(int amount)
{
List<int> coins = new List<int> { 10, 5, 1 }; // 可用的硬幣面值
List<int> change = new List<int>();
int remaining = amount;
foreach (int coin in coins)
{
while (remaining >= coin)
{
change.Add(coin);
remaining -= coin;
}
}
return change;
}
static void Main(string[] args)
{
int amount = 15;
List<int> change = FindChange(amount);
Console.WriteLine("找零錢的硬幣:");
foreach (int coin in change)
{
Console.Write(coin + " ");
}
}
基本概念:
程式實作(10的n次方):
double CalculatePower(double baseNumber, int exponent)
{
double result = 1.0;
for (int i = 0; i < exponent; i++)
{
result *= baseNumber;
}
return result;
}
public static void Main()
{
double baseNumber = 10.0;
int exponent = 5; // 將10的5次方
double result = CalculatePower(baseNumber, exponent);
Console.WriteLine($"10的{exponent}次方為: {result}");
}
期望挑戰30天持續更新成功 ~ DAY22